package com.ruoyi.quantify.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import com.ruoyi.quantify.domain.QuantifyStudent;
import com.ruoyi.quantify.service.IQuantifyStudentService;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 量化考核Controller
 * 
 * @author yepanpan
 * @date 2021-05-14
 */
@Api("量化考核管理")
@RestController
@RequestMapping("/quantify/student")
public class QuantifyStudentController extends BaseController
{
    @Autowired
    private IQuantifyStudentService quantifyStudentService;
	  /**
     * 查询量化考核列表
     */
    @ApiOperation("查询量化考核列表")   
    @PreAuthorize("@ss.hasPermi('quantify:student:my')")
    @GetMapping("/my")
    public TableDataInfo my(QuantifyStudent quantifyStudent)
    {
    	quantifyStudent.setStuId(SecurityUtils.getLoginUser().getUser().getUserId());
        startPage();
        List<QuantifyStudent> list = quantifyStudentService.selectQuantifyStudentList(quantifyStudent);
        return getDataTable(list);
    }
    

    /**
     * 查询量化考核列表
     */
    @ApiOperation("查询量化考核列表")   
    @GetMapping("/teacher")
    public TableDataInfo teacher(QuantifyStudent quantifyStudent)
    {
    	quantifyStudent.getParams().put("teacherId", SecurityUtils.getLoginUser().getUser().getUserId());
        startPage();
        List<QuantifyStudent> list = quantifyStudentService.selectQuantifyStudentList(quantifyStudent);
        return getDataTable(list);
    }
    
    /**
     * 查询量化考核列表
     */
    @ApiOperation("查询量化考核列表")   
    @GetMapping("/list")
    public TableDataInfo list(QuantifyStudent quantifyStudent)
    {
        startPage();
        List<QuantifyStudent> list = quantifyStudentService.selectQuantifyStudentList(quantifyStudent);
        return getDataTable(list);
    }

    /**
     * 导出量化考核列表
     */
    @ApiOperation("导出量化考核列表")    
    @PreAuthorize("@ss.hasPermi('quantify:student:export')")
    @Log(title = "量化考核", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QuantifyStudent quantifyStudent)
    {
        List<QuantifyStudent> list = quantifyStudentService.selectQuantifyStudentList(quantifyStudent);
        ExcelUtil<QuantifyStudent> util = new ExcelUtil<QuantifyStudent>(QuantifyStudent.class);
        return util.exportExcel(list, "student");
    }

    /**
     * 获取量化考核详细信息
     */
    @ApiOperation("获取量化考核详细信息")
    @ApiImplicitParam(name = "id", value = "量化考核ID", required = true, dataType = "int", paramType = "path") 
    @PreAuthorize("@ss.hasPermi('quantify:student:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(quantifyStudentService.selectQuantifyStudentById(id));
    }

    /**
     * 新增量化考核
     */
    @ApiOperation("新增量化考核")
    @PreAuthorize("@ss.hasPermi('quantify:student:add')")
    @Log(title = "量化考核", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QuantifyStudent quantifyStudent)
    {
        return toAjax(quantifyStudentService.insertQuantifyStudent(quantifyStudent));
    }

    /**
     * 修改量化考核
     */
    @ApiOperation("修改量化考核")  
    @PreAuthorize("@ss.hasPermi('quantify:student:edit')")
    @Log(title = "量化考核", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QuantifyStudent quantifyStudent)
    {
        return toAjax(quantifyStudentService.updateQuantifyStudent(quantifyStudent));
    }

    /**
     * 删除量化考核
     */
    @ApiOperation("删除量化考核")
    @ApiImplicitParam(name = "id", value = "量化考核ID", required = true, dataType = "int", paramType = "path") 
    @PreAuthorize("@ss.hasPermi('quantify:student:remove')")
    @Log(title = "量化考核", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(quantifyStudentService.deleteQuantifyStudentByIds(ids));
    }
    
    @Log(title = "导入学生信息", businessType = BusinessType.IMPORT)
	@PreAuthorize("@ss.hasPermi('base:student:import')")
	@PostMapping("/importData")
	public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
		ExcelUtil<QuantifyStudent> util = new ExcelUtil<QuantifyStudent>(QuantifyStudent.class);
		List<QuantifyStudent> studentList = util.importExcel(file.getInputStream());
		String operName = SecurityUtils.getUsername();
		String message = quantifyStudentService.imports(studentList, updateSupport, operName);
		return AjaxResult.success(message);
	}

	@GetMapping("/importTemplate")
	public AjaxResult importTemplate() {
		ExcelUtil<QuantifyStudent> util = new ExcelUtil<QuantifyStudent>(QuantifyStudent.class);
		return util.importTemplateExcel("学生量化考核数据");
	}
}
